


package btracker;

import javax.swing.UIManager.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

 /**
 * The main window containing all features used in the budget tracker
 *
 * @author (c) Sammy guergachi 2009-2010
 * @version Feb 25 2010
 */


public class MainWindow {

    static JFrame mainFrame; //Main widnow contaning all components
    static JLabel lblStatus; //display current status of Application
    static JLabel lblCurrentBudget; //display the current budget value set by user
    static JLabel lblCurrentBalance; // display the current balance
    static JLabel lblWarning; // displays if user has not set buget yet
    static JButton btnSetBudget; // diplays dialog box to set budget
    static JButton btnNewCategory; //alow user to input a new data entery in the database
    static JButton btnRemoveCategory;// allow user to remove selected data entery
    static JComboBox cmbTypeOfBalance;//shows the type of balance
    static JTree treeCategory; // a simple tree with categories containing all the data
    static JPanel pnlDataTable; //panel containg table with all data
    static JPanel pnlCalendar; // panel containing a Calendar from the Calendar class
    static JPanel pnlReport; // Panel containg the Reports view
    static JTabbedPane Tabs;// tabs to alow user to go through the diffrent
                                    // fuctions of the application
    static JMenuBar menuBar; // menu bar

    public static void mainGUI() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException, InterruptedException {


                      



///////   Uper Components declare
        JPanel btnPanel = new JPanel(); // contains btnNewCategory and btnRemoveCategory
        treeCategory = new JTree();



/////// Run DataTable
        DataTable.drawTable();

/////// Run Calendar
        
        Calendar.drawCalendar();
        
        pnlCalendar.setPreferredSize(new Dimension(850, 550));
       
////// Run Report
        Report.drawReport();


//          Tabs config             //
        Tabs = new JTabbedPane();
        Tabs.add(pnlCalendar, 0);
        Tabs.setTitleAt(0, "Calender");
        Tabs.add(pnlDataTable, 1);
        Tabs.setTitleAt(1, "Data Table");
        Tabs.add(pnlReport, 2);
        Tabs.setTitleAt(2, "Reports");
//                                  //


//          Menu Bar Config    //
        menuBar = new JMenuBar();

        JMenu menuFile = new JMenu("File");

        JMenuItem mnuSave = new JMenuItem("Save");
        JMenuItem mnuOpen = new JMenuItem("Open");

        menuFile.add(mnuSave);
        menuFile.add(mnuOpen);
        menuBar.add(menuFile);

//                            //


//              uperPanel config             //
        JPanel uperPanel = new JPanel(new BorderLayout());
        JPanel uperLeftPanel = new JPanel();
        JPanel uperRightPanel = new JPanel();
        uperLeftPanel.setLayout(new GridLayout(2, 0, 5, 0));
        uperPanel.add(BorderLayout.WEST, uperLeftPanel);
        uperPanel.add(BorderLayout.EAST, uperRightPanel);
        uperPanel.add(BorderLayout.PAGE_START, menuBar);

//                                           //




///////////Uper Left panel


        uperLeftPanel.add(treeCategory);


//////////Uper Right panel
        uperRightPanel.add(Tabs);



        //        lowerPanel config        //
        JPanel lowerPanel = new JPanel(new BorderLayout());
        JPanel leftPanel = new JPanel(new GridLayout(2, 3, 30, 10));
        //                                  //

        lblCurrentBudget = new JLabel("Current Budget: [not set]");
        lblStatus = new JLabel("                        Status: Ready.");
        lblCurrentBalance = new JLabel("Current Balance: $0");




        //     Buttons Config                  //

        ButtonHandler onClick = new ButtonHandler();

        btnSetBudget = new JButton("Set Budget");
        btnSetBudget.addActionListener(onClick);
        btnSetBudget.setActionCommand("setBudget");

        btnNewCategory = new JButton("New Category");
        btnNewCategory.addActionListener(onClick);
        btnNewCategory.setActionCommand("newCategory");

        btnRemoveCategory = new JButton("Remove Category");
        btnRemoveCategory.addActionListener(onClick);
        btnRemoveCategory.setActionCommand("removeCategory");

        //                                    //


///////// Lower panels Config
        cmbTypeOfBalance = new JComboBox();
        lblWarning = new JLabel("(!) Budget Has Not Been Set    ");



        btnPanel.add(btnNewCategory, new GridLayout(0, 2));
        btnPanel.add(btnRemoveCategory, new GridLayout(0, 2));

        lowerPanel.add(leftPanel, BorderLayout.AFTER_LINE_ENDS);
        lowerPanel.add(btnPanel, BorderLayout.WEST);

        leftPanel.add(lblCurrentBudget);
        leftPanel.add(lblCurrentBalance);
        leftPanel.add(lblWarning);
        leftPanel.add(btnSetBudget);
        leftPanel.add(cmbTypeOfBalance);
        leftPanel.add(lblStatus);



////////        mainFrame config          //
        ///set up window
        mainFrame = new JFrame("Budget Tracker V 0.31");
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        mainFrame.setSize(1000, 700);
        mainFrame.setLocationRelativeTo(null);
        mainFrame.setVisible(true);
        

//                                  //

        mainFrame.add(BorderLayout.SOUTH, lowerPanel);
        mainFrame.add(BorderLayout.NORTH, uperPanel);
       


    }

    private static class ButtonHandler implements ActionListener {

        public void actionPerformed(ActionEvent e) {



            String command = e.getActionCommand();

            if (command.equals("setBudget")) {

                SetBudget.setBudgetGUI();


            } else if (command.equals("newcategory")) {
            } else if (command.equals("removeCategory")) {
            }
        }
    }
}

